/**
 *    Copyright 2009-2016 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.transaction;

import java.sql.Connection;
import java.sql.SQLException;

/**Mybatis事务有两个作用：1、获取jdbc中的Connection对象；2、对事务进行提交或者回滚操作
 * <br/>Executor组件就是通过Transaction对象获取jdbc的Connection对象，进而完成与数据库的交互
 * <br/>Wraps a database connection. Handles the connection lifecycle that comprises:
 * its creation, preparation, commit/rollback and close.
 *
 * @author Clinton Begin
 */
public interface Transaction {

	/**获取连接对象
	 * <br/>Retrieve inner database connection
	 * 
	 * @return DataBase connection
	 * @throws SQLException
	 */
	Connection getConnection() throws SQLException;

	/**提交事务
	 * <br/>Commit inner database connection.
	 * 
	 * @throws SQLException
	 */
	void commit() throws SQLException;

	/**回滚事务
	 * <br/>Rollback inner database connection.
	 * 
	 * @throws SQLException
	 */
	void rollback() throws SQLException;

	/**关闭连接
	 * <br/>Close inner database connection.
	 * 
	 * @throws SQLException
	 */
	void close() throws SQLException;

	/**获取超时时间
	 * <br/>Get transaction timeout if set
	 * 
	 * @throws SQLException
	 */
	Integer getTimeout() throws SQLException;

}
